package lab.gene.action;

import java.util.Date;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lab.gene.service.impl.GenePrepIntermediatesServiceImpl;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;

public class UpdateGenePrepIntermediatesAction extends ActionSupport implements ServletResponseAware, ServletRequestAware {
	
	private static final long serialVersionUID = 1L;
	protected HttpServletResponse servletResponse;  
	@Override   
	public void setServletResponse(HttpServletResponse servletResponse) {   
		this.servletResponse = servletResponse;   
	}   
	
	protected HttpServletRequest servletRequest;   
	@Override   
	public void setServletRequest(HttpServletRequest servletRequest) {   
		this.servletRequest = servletRequest;   
	} 
	
	private String geneName;
	private String type;
	private Date date1;
	private Date date2;
	private String x1;
	private String x2;
	private String y1;
	private String y2;
	private String z1;
	private String z2;
	private String pcrX1;
	private String pcrX2;
	private String pcrY1;
	private String pcrY2;
	private String pcrZ1;
	private String pcrZ2;
	private String userName;
	private Date dateModified;
	private String checked;
	private String repeatChecked;
	
	public String execute() {
		String result = null;
		
		Cookie[] cookies = servletRequest.getCookies();
		String cookieName = "LabUser";
		userName = null;
		if (cookies != null) {
			for (int i = 0; i < cookies.length; i++) {
				if (cookies[i].getName().equals(cookieName)) {
					userName = cookies[i].getValue();
					break;
				}
			}
		}
		int vx1 = 0, vx2 = 0, vy1 = 0, vy2 = 0, vz1 = 0, vz2 = 0;
		System.out.println("updateGeneIntermediates!!!");
		System.out.println("service1");
		vx1 = (x1 != null && x1.length() != 0)? Integer.valueOf(x1) : 0;
		vx2 = (x2 != null && x2.length() != 0)? Integer.valueOf(x2) : 0;
		vy1 = (y1 != null && y1.length() != 0)? Integer.valueOf(y1) : 0;
		vy2 = (y2 != null && y2.length() != 0)? Integer.valueOf(y2) : 0;
		vz1 = (z1 != null && z1.length() != 0)? Integer.valueOf(z1) : 0;
		vz2 = (z2 != null && z2.length() != 0)? Integer.valueOf(z2) : 0;
		System.out.println("service");
		GenePrepIntermediatesServiceImpl service = new GenePrepIntermediatesServiceImpl();
		service.addGenePrepIntermediates(geneName, type, date1, date2, pcrX1, pcrY1, pcrZ1, pcrX2, pcrY2, pcrZ2, vx1, vx2, vy1, vy2, vz1, vz2, checked, repeatChecked, userName);

		//System.out.println("checked="+checked);
		//System.out.println("repeatChecked="+repeatChecked);
		switch (type){
			case "B":
				result = "successB";
				break;
			case "C":
				result = "successC";
				break;
			case "D":
				result = "successD";
				break;
		}
		return result;
	}
	
	
	public String getGeneName() {
		return geneName;
	}
	public void setGeneName(String geneName) {
		this.geneName = geneName;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Date getDate1() {
		return date1;
	}
	public void setDate1(Date date1) {
		this.date1 = date1;
	}
	public Date getDate2() {
		return date2;
	}
	public void setDate2(Date date2) {
		this.date2 = date2;
	}
	
	public String getPcrX1() {
		return pcrX1;
	}
	public void setPcrX1(String pcrX1) {
		this.pcrX1 = pcrX1;
	}
	public String getPcrX2() {
		return pcrX2;
	}
	public void setPcrX2(String pcrX2) {
		this.pcrX2 = pcrX2;
	}
	public String getPcrY1() {
		return pcrY1;
	}
	public void setPcrY1(String pcrY1) {
		this.pcrY1 = pcrY1;
	}
	public String getPcrY2() {
		return pcrY2;
	}
	public void setPcrY2(String pcrY2) {
		this.pcrY2 = pcrY2;
	}
	public String getPcrZ1() {
		return pcrZ1;
	}
	public void setPcrZ1(String pcrZ1) {
		this.pcrZ1 = pcrZ1;
	}
	public String getPcrZ2() {
		return pcrZ2;
	}
	public void setPcrZ2(String pcrZ2) {
		this.pcrZ2 = pcrZ2;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public Date getDateModified() {
		return dateModified;
	}
	public void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}
	public String getChecked() {
		return checked;
	}
	public void setChecked(String checked) {
		this.checked = checked;
	}
	public String getRepeatChecked() {
		return repeatChecked;
	}
	public void setRepeatChecked(String repeatChecked) {
		this.repeatChecked = repeatChecked;
	}


	public String getX1() {
		return x1;
	}


	public void setX1(String x1) {
		this.x1 = x1;
	}


	public String getX2() {
		return x2;
	}


	public void setX2(String x2) {
		this.x2 = x2;
	}


	public String getY1() {
		return y1;
	}


	public void setY1(String y1) {
		this.y1 = y1;
	}


	public String getY2() {
		return y2;
	}


	public void setY2(String y2) {
		this.y2 = y2;
	}


	public String getZ1() {
		return z1;
	}


	public void setZ1(String z1) {
		this.z1 = z1;
	}


	public String getZ2() {
		return z2;
	}


	public void setZ2(String z2) {
		this.z2 = z2;
	}
	
	
}
